package io;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 包装流-BufferedWriter
 */
public class BufferedWriter_ {

    public static void main(String[] args) throws Exception {

        String filePath = "D:\\IdeaCode\\javaStudy\\ok.txt";

        //创建一个BufferedWriter
        /*
            new FileWriter(filePath) 默认以覆盖方式创建
            new FileWriter(filePath, true) 以追加方式创建
         */
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath));   //默认覆盖
        //插入换行符
        bufferedWriter.write("hello, lmy!");
        bufferedWriter.newLine();//插入一个换行符
        bufferedWriter.write("hello2, lmy!");
        bufferedWriter.newLine();
        bufferedWriter.write("hello3, lmy!");

        //关闭外层流，内部节点流会自动关闭
        bufferedWriter.close();
    }
}
